var win = Ti.UI.currentWindow;

Ti.include('background.js');

win.add(headerView);
win.add(viewContainer);
showLoading();

var viewScrollContainer = Ti.UI.createView({
//    contentWidth:'auto',
//    contentHeight:'auto',		    
//    showVerticalScrollIndicator:true,
//    showHorizontalScrollIndicator:false,
//	scrollType: 'vertical',
//	backgroundColor: viewport_bg,
//	opacity: 0.30,
//	borderRadius: 10,
//	borderColor: viewport_border,
//	borderWidth: 2,
	width: 280,
	height: 390,
	top: 0,
	left: 20
});		

viewContainer.add(viewScrollContainer);

var url = 'http://www.dotnetnuke.com/Community/Blogs/tabid/825/rssid/0/Default.aspx';

// create table view data object
var data = [];

var xhr = Ti.Network.createHTTPClient();
xhr.open("GET", url);
xhr.onload = function() {
	try {
		var doc = this.responseXML.documentElement;
		var items = doc.getElementsByTagName("item");

		//var doctitle = doc.evaluate("//channel/title/text()").item(0).nodeValue;
		for ( var c = 0; c < items.length; c++) {
			var item = items.item(c);
			var title = item.getElementsByTagName("title").item(0).text;
			var pubdate = item.getElementsByTagName('pubDate').item(0).text;
			var row = Ti.UI.createTableViewRow({height: 40});
			var label = Ti.UI.createLabel( {
				text : title,
				left : 5,
				top : 5,
				height : 16,
				right : 5,
				font: {fontSize:12, fontWeight:'bold'},
				color: '#fff'
			});
			row.add(label);

			var author = Ti.UI.createLabel( {
				text : pubdate,
				left : 5,
				right : 5,
				height : 14,
				bottom: 5,
				font: {fontSize:10, fontWeight:'bold'},
				color: '#bb0'
			});
			
			row.add(author);			
			
			row.url = item.getElementsByTagName("link").item(0).text;
			row.className = 'rss_row';
			data.push(row);
		}
	
		var tableview = Ti.UI.createTableView( {
			data : data,
			top: 10,
			bottom: 10,
			width: viewScrollContainer.size.width,
			height: viewScrollContainer.size.height - 20,
			separatorColor:'transparent'
		});

		viewScrollContainer.add(tableview);

		tableview.addEventListener('click', function(e) {
			Ti.App.Properties.setString('browser_url', e.row.url + '#2612');
			var browser = Ti.UI.createWindow( {
				url: 'browser.js',
				navBarHidden: true,
			    backgroundImage:DotNetNuke.getBackgroundImage()
			});
			browser.open();
//			Ti.Platform.openURL(e.row.url);

		});
	} catch (E) {
		alert(E);
	}
	hideLoading();
};
xhr.send();
